From 3ebb8eb3a3d9fa9d05977210ded474fc45d20aed Mon Sep 17 00:00:00 2001 From: debris Date: Fri, 11 Aug 2017 17:39:18 +0200 Subject: [PATCH] Fix implementation and tests for cannot-be-a-base-url canonicalization --- src/cargo/sources/git/source.rs | 22 ++++++---------------- tests/install.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index ed156af83..6a5154b2e 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -76,13 +76,10 @@ fn ident(url: &Url) -> CargoResult { pub fn canonicalize_url(url: &Url) -> CargoResult { let mut url = url.clone(); + // cannot-be-a-base-urls are not supported + // eg. github.com:rust-lang-nursery/rustfmt.git if url.cannot_be_a_base() { - if url.scheme() != "github.com" { - return Err(format!("invalid url `{}`: cannot-be-a-base-URLs are not supported", url).into()); - } - // it's most likely an attempt to fetch github repo - // https://github.com/rust-lang/cargo/issues/4394 - url = Url::parse(&format!("https://github.com/{}", url.path())).unwrap(); + return Err(format!("invalid url `{}`: cannot-be-a-base-URLs are not supported", url).into()); } // Strip a trailing slash @@ -245,22 +242,15 @@ mod test { } #[test] - fn test_canonicalize_idents_different_protocls() { + fn test_canonicalize_idents_different_protocols() { let ident1 = ident(&url("https://github.com/PistonDevelopers/piston")).unwrap(); let ident2 = ident(&url("git://github.com/PistonDevelopers/piston")).unwrap(); assert_eq!(ident1, ident2); } #[test] - fn test_canonicalize_github_not_a_base_urls() { - let ident1 = ident(&url("github.com:PistonDevelopers/piston")).unwrap(); - let ident2 = ident(&url("https://github.com/PistonDevelopers/piston")).unwrap(); - assert_eq!(ident1, ident2); - } - - #[test] - fn test_canonicalize_not_a_base_urls() { - assert!(ident(&url("github.com:PistonDevelopers/piston")).is_ok()); + fn test_canonicalize_cannot_be_a_base_urls() { + assert!(ident(&url("github.com:PistonDevelopers/piston")).is_err()); assert!(ident(&url("google.com:PistonDevelopers/piston")).is_err()); } diff --git a/tests/install.rs b/tests/install.rs index 9d385551b..5527f1628 100644 --- a/tests/install.rs +++ b/tests/install.rs @@ -902,3 +902,11 @@ historically Cargo treated this as a semver version requirement accidentally and will continue to do so, but this behavior will be removed eventually ")); } + +#[test] +fn test_install_git_cannot_be_a_base_url() { + assert_that(cargo_process("install").arg("--git").arg("github.com:rust-lang-nursery/rustfmt.git"), + execs().with_status(101).with_stderr("\ +error: invalid url `github.com:rust-lang-nursery/rustfmt.git`: cannot-be-a-base-URLs are not supported +")); +} -- 2.30.2